package com.xl.interfacedemo;

import java.util.ArrayList;

public class StudentOperatorImpl2 implements StudentOperator{
    @Override
    public void printAllInfo(ArrayList<Student> students) {
        System.out.println("--------------全班全部学生信息如下：");
        int count1 = 0;
        int count2 = 0;
        for (Student student : students) {
            if (student.getSex() == '男') {
                count1++;
            } else {
                count2++;
            }
            System.out.println(student.getName() + " " + student.getSex() + " " + student.getScore());
        }
        System.out.println("男生：" + count1 + "名，女生：" + count2 + "名");
        System.out.println("班级总人数："+students.size()+"名");
        System.out.println("-----------------------");
    }

    @Override
    public void printAverageScore(ArrayList<Student> students) {
        System.out.println("--------------全班各科平均分如下：");
        double sum = 0;
        double max = students.get(0).getScore();
        double min = students.get(0).getScore();
        for (Student student : students) {
            if (student.getScore() > max) {
                max = student.getScore();
            }
            if (student.getScore() < min) {
                min = student.getScore();
            }
            sum += student.getScore();
        }
        System.out.println("最高分：" + max);
        System.out.println("最低分：" + min);
        System.out.println("平均分：" + (sum-max-min) / (students.size()-2));
    }
}
